/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vue;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.SpringLayout;

/**
 *
 * @author clement
 */
public class FenetreOption extends JDialog {
    
    private JPanel panelPrincipale;
    private JPanel panelTaille;
    private JPanel panelTaille2;
    private JPanel panelBoutons;
    private JPanel panelRadio;
    private JPanel panelRadio2;
    private JLabel labelTitreTaille;
    private JLabel labelTitreForme;
    private JRadioButton carre;
    private JRadioButton triangle;
    private JRadioButton hexa;
    private ButtonGroup groupRadio;
    private JLabel labelHauteur;
    private JLabel labelLargeur;
    private JSpinner hauteur;
    private JSpinner largeur;
    private JButton valider;
    private JButton annuler;
    
    public FenetreOption(JFrame parent, int largeurActuelle, int hauteurActuelle, int forme)
    {
        super(parent, true);
        panelPrincipale = new JPanel();
        panelPrincipale.setLayout(new BoxLayout(panelPrincipale, BoxLayout.PAGE_AXIS));
        panelTaille = new JPanel();
        panelTaille.setLayout(new SpringLayout());
        panelTaille2 = new JPanel();
        panelBoutons = new JPanel();
        panelRadio = new JPanel();
        panelRadio.setLayout(new SpringLayout());
        panelRadio2 = new JPanel();
        labelTitreForme = new JLabel("Choisir une forme:");
        labelTitreTaille = new JLabel("Taille de la grille:");
        labelHauteur = new JLabel("Hauteur");
        labelLargeur = new JLabel("Largeur");
        hauteur = new JSpinner();
        largeur = new JSpinner();
        hauteur.setModel(new javax.swing.SpinnerNumberModel(15, 1, 100, 1));
        largeur.setModel(new javax.swing.SpinnerNumberModel(15, 1, 100, 1));
        hauteur.setValue(hauteurActuelle);
        largeur.setValue(largeurActuelle);
        
        valider = new JButton("Valider");
        annuler = new JButton("Annuler");
        panelBoutons.add(annuler);
        panelBoutons.add(valider);
        
        carre = new JRadioButton("Carrée");
        triangle = new JRadioButton("Triangle");
        hexa = new JRadioButton("Hexagonale");
        
        groupRadio = new ButtonGroup();
        groupRadio.add(carre);
        groupRadio.add(triangle);
        groupRadio.add(hexa);
        if(forme == Fenetre.CARRE)
            carre.setSelected(true);
        else if(forme == Fenetre.TRIANGLE)
            triangle.setSelected(true);
        else
            hexa.setSelected(true);
           
        
        panelRadio.add(labelTitreForme);
        panelRadio2.add(carre);
        panelRadio2.add(triangle);
        panelRadio2.add(hexa);
        panelRadio.add(panelRadio2);
        SpringLayout sp = (SpringLayout) panelRadio.getLayout();
        sp.putConstraint(SpringLayout.WEST, labelTitreForme, 5, SpringLayout.WEST, this);
        sp.putConstraint(SpringLayout.WEST, panelRadio2, 10, SpringLayout.WEST, this);
        sp.putConstraint(SpringLayout.NORTH, panelRadio2, 15, SpringLayout.NORTH, labelTitreForme);
        
        panelTaille.add(labelTitreTaille);
        panelTaille2.add(labelLargeur);
        panelTaille2.add(largeur);
        panelTaille2.add(labelHauteur);
        panelTaille2.add(hauteur);
        panelTaille.add(panelTaille2);
        sp = (SpringLayout) panelTaille.getLayout();
        sp.putConstraint(SpringLayout.WEST, labelTitreTaille, 5, SpringLayout.WEST, this);
        sp.putConstraint(SpringLayout.NORTH, labelTitreTaille, 15, SpringLayout.NORTH, this);
        sp.putConstraint(SpringLayout.WEST, panelTaille2, 10, SpringLayout.WEST, this);
        sp.putConstraint(SpringLayout.NORTH, panelTaille2, 15, SpringLayout.NORTH, labelTitreTaille);
        
        
        panelPrincipale.add(panelTaille);
        panelPrincipale.add(panelRadio);
        panelPrincipale.add(panelBoutons);
        
        setSize(400,210);
        setTitle("Options");
        this.add(panelPrincipale);
    }
    
    public JButton getAnnuler(){
        return annuler;
    }
    
    public JButton getValider(){
        return valider;
    }
    
    public Integer getHauteur(){
        return (Integer) hauteur.getValue();
    }
    
    public Integer getLargeur(){
        return (Integer) largeur.getValue();
    }
    
    public int getForme(){
        if(carre.isSelected())
            return Fenetre.CARRE;
        else if(triangle.isSelected())
            return Fenetre.TRIANGLE;
        else
            return Fenetre.HEXA;
    }
}
